#include "PFS.h"

//FILE * pFile;
t_pfs pPfs;

static int fuselage_getattr(const char *path, struct stat *stbuf)
{
int res = 0;
t_fdtCompleteEntry * entradaDelArchivo;

if(getAttrFalso(path)) return - ENOENT;



if(strcmp(path, "/") == 0) {
          stbuf->st_mode = S_IFDIR | 0755;
          stbuf->st_nlink = 2;
          return res;
}
/*
entradaDelArchivo = (t_fdtCompleteEntry *)malloc(sizeof(t_fdtCompleteEntry));
if(!fdtEntryDePath(path,entradaDelArchivo ))return -ENOENT;



//    else
//       res = -ENOENT;

//   return res;


*/

}

static int fuselage_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
                         off_t offset, struct fuse_file_info *fi)
{
	 printf("EN FUSELAGE READDIR \n");
	 fflush(stdin);

}

static int fuselage_open(const char *path, struct fuse_file_info *fi)
{
	   if((fi->flags & 3) != O_RDONLY)
	        return -EACCES;

	    return 0;

//return -errno; ????????
}
static struct fuse_operations fuselage_oper = {
    .getattr   = fuselage_getattr,
    .readdir = fuselage_readdir,
    .open   = fuselage_open,
 };


int main(int argc, char *argv[])
{

	//Lee el archivo de configuracion, lee el bootsector y hace el pool e conexiones
   if(!incicializarPfs()){
    return 0;
      }
   printf("Se inicializo bien \n");
    int   argc_fuse=4;
	char *argv_fuse[] = { "/home/utn_so/Desarrollo/TP_OPS/Fuselage_PFS/Debug/Fuselage_PFS" , "/home/utn_so/Desarrollo/TP_OPS/Fuselage_PFS/Debug/testFolder" , "-d","-s"};
	t_cluster * cluster0;

	//obtenerArrayPathDePath("/hola/pepe/yiyo");
	//cluster0 = armarCluster(0);
//	printf("cl %d",cluster0->bloques->elements_count );
//	printf("AAAAAAAAAAA %d",collection_list_size(cluster0->bloques));
	fflush(stdin);
//	pedirClusterArmado(cluster0);
t_cache_archivo * arch;
agregarCacheParaPath("/test.txt",arch);

//	t_cluster *clust=collection_list_get(pPfs.cacheArchivos.root.listaClusters,0);

//t_list * list= 	buscarTodasLasFdtEntryEnCluster(clust);
//	t_fdtCompleteEntry * fdtEntry;
//	t_cache_archivo * entradaCache;
//	entradaCache = (t_cache_archivo *)malloc(sizeof(t_cache_archivo));
//	fdtEntry = (t_fdtCompleteEntry *)malloc(sizeof(t_fdtCompleteEntry));
//t_cluster * clustRoot = collection_list_get(pPfs.cacheArchivos.root.listaClusters,0);
//t_list * entr =	buscarTodasLasFdtEntryEnCluster(clustRoot);
//t_fdtCompleteEntry * entrada = collection_list_get(entr,0);
//	fdtEntryDePath("/Carpeta1/ach.txt",fdtEntry,entradaCache);
	//fdtEntryDePath("/test.txt",fdtEntry,entradaCache);


//	getchar();
	return fuse_main(argc_fuse, argv_fuse, &fuselage_oper, NULL);


   return 1;
}




int32_t getAttrFalso(const char *path){
	  return (strcmp(path, "/.Trash") == 0 || strcmp(path, "/.Trash-1000") == 0 );
}
